<template>
  <base-breadcrumb :title="$route.meta.title">
    <!-- 质量创优申报资料库 -->
    <div id="base-breadcrumb" style="position: relative; overflow: hidden">
      <!-- 搜索 -->
      <searchData :searchData="searchArr" @search="search"></searchData>
      <!-- 表格 -->
      <a-card :bordered="false">
        <!-- <title-name :title="$route.meta.title"></title-name> -->
        <!-- 表格 -->
        <list-table ref="table" tableLayout="fixed" size="default" :columns="columns" :request="loadData">
          <a-button slot="prefix" v-btnPermission="[
                      {
                        ident: 'prma_seex',
                        code: 'seex_qm_046_add_01'
                      },
                      {
                        ident: 'prma_buco',
                        code: 'buco_qm_046_add_01'
                      }
              ]" icon="plus" type="primary" @click="handleManage(2)"
            >新增质量创优申报资料</a-button
          >
          <template slot="action" slot-scope="text, record">
            <MoreButton>
            <a v-btnPermission="[
                      {
                        ident: 'prma_seex',
                        code: 'seex_qm_046_loo_04'
                      },
                      {
                        ident: 'prma_buco',
                        code: 'buco_qm_046_loo_04'
                      }
              ]" @click="handleManage(0, record)">查看</a>
            <!-- 公司人员可编辑所有的，分公司人员只能编辑自己分公司的 -->
            <template
              v-if="
                record.submitLevel === $currentPost().code &&
                $currentPost().id ===
                  { CO: record.companyId, BC: record.branchComId, PD: record.projectDeptOrgId }[$currentPost().code]
              "
            >
              <a v-btnPermission="[
                      {
                        ident: 'prma_seex',
                        code: 'seex_qm_046_edi_02'
                      },
                      {
                        ident: 'prma_buco',
                        code: 'buco_qm_046_edi_02'
                      }
              ]" @click="handleManage(1, record)">编辑</a>
              <a v-btnPermission="[
                      {
                        ident: 'prma_seex',
                        code: 'seex_qm_046_del_03'
                      },
                      {
                        ident: 'prma_buco',
                        code: 'buco_qm_046_del_03'
                      }
              ]" @click="handleRemove(record.id)">删除</a>
            </template>
            </MoreButton>
          </template>
        </list-table>
      </a-card>
    </div>
  </base-breadcrumb>
</template>

<script>
import { excellenceApplication } from '@/api/quality/quality' // api
import SelectSubCompany from '@/components/Select/SelectSubCompany' // 分公司
import SelectProject from '@/components/Select/SelectProject' // 项目名称
import OrgTreeSelect from '@/components/OrgTreeSelect'
import Selector from '@/components/Select/Selector' // 枚举名称
import BasePage from '@/views/basePage'
import SelectProjectStatus from '@/views/quality/components/SelectProjectStatus' // 项目状态

const searchArr = [
  // 搜索框
  {
    name: '所属单位',
    valueKey: 'searchQuery',
    type: OrgTreeSelect,
  },
  // {
  //   name: '所属分公司',
  //   type: SelectSubCompany,
  //   valueKey: 'branchComId'
  // },
  // {
  //   name: '所属项目',
  //   type: SelectProject,
  //   valueKey: 'projectId',
  //   keyValue: 'branchComId'
  // },
  {
    name: '项目状态',
    type: SelectProjectStatus,
    valueKey: 'projectStatus'
  },
  {
    name: '奖项名称',
    type: Selector,
    valueKey: 'prizeNameId',
    selectType: '52'
  }
]
const columns = [
  {
    title: '序号',
    dataIndex: 'index',
    width: 80,
    customRender() {
      return arguments[2] + 1
    }
  },
  {
    title: '分公司',
    ellipsis: true,
    dataIndex: 'branchComName'
  },
  {
    title: '项目',
    ellipsis: true,
    dataIndex: 'projectName'
  },
  {
    title: '奖项名称',
    ellipsis: true,
    dataIndex: 'recordName'
  },
  {
    title: '申报时间',
    dataIndex: 'declareDate'
  },
  {
    title: '申报人',
    dataIndex: 'declareEmployeeName'
  },
  {
    title: '操作',
    dataIndex: 'action',
    width: '180px',
    align: 'center',
    scopedSlots: { customRender: 'action' }
  }
]
export default {
  name: 'a' + Date.now(),
  extends: new BasePage(),
  data() {
    this.columns = columns
    this.searchArr = searchArr
    return {
      queryParam: {}, // 查询参数
      removeApi: excellenceApplication,
      // 加载数据方法 必须为 Promise 对象
      loadData: (parameter) => {
        const requestParameters = Object.assign({}, parameter, this.queryParam)
        return excellenceApplication.postList(requestParameters).then((res) => {
          return res
        })
      },
      editModel: 0,
      form: {}
    }
  },
  methods: {
    // 搜索
    search(value) {
      value && (this.queryParam = value)
      this.$refs.table.refresh(true)
      this.loadCount++
    },
    // 操作栏
    handleManage(type, record) {
      this.editModel = type
      let query = {
        editModel: type
      }
      if (record && record.id) {
        query.id = record.id
      }
      this.$router.push({
        name: 'excellenceApplicationEdit',
        query
      })
    }
  }
}
</script>
